#include "devices.h"

DEF_UART_BUF( u0buf, 32 );
DEF_UART_BUF( u1buf, 32 );
static void init_stdio( void );
void devices_init( void )
{
	uart_init( 0, ub115200, u0buf, u0bufSz );
	uart_init( 1, ub115200, u1buf, u1bufSz );
	init_stdio();
	lcd_init();
	init_stdio();
	sysclk_init( ( _BV(CS01) | _BV(CS02) ), 256, 1000  );/*初始化系统时钟，使用第一个定时器*/
}

/* 在这里声明你的中断服务程序 */
UART_ISR( 0 )
UART_ISR( 1 )

#ifdef _STDIO_H_
static FILE lcdf;
static uint8_t lcd_line = 0;
FILE *get_lcd_file( void )
{
	return &lcdf;
}
static int lcdf_putc( char c, FILE *stream )
{
	if( c == '\n' || c=='\r' ){
		lcd_line = !lcd_line;
		lcd_set_xy( 0, lcd_line );
	}
	lcd_putc( c );
	return 0;
}
static void lcd_open( void )
{
	fdev_setup_stream( &lcdf, lcdf_putc, NULL, __SWR );
}
static void init_stdio( void )
{
	lcd_open();
	stdout = &lcdf;
	stderr = &lcdf;
}
#else
static void init_stdio( void )
{
}
#endif
